<template>
	<div class="orrOutcupEfficiencyDetail-add-update-component">
		<el-dialog
				v-if="modelValue.visible"
				v-model="modelValue.visible"
				:title="
        !modelValue.form.id
          ? `新增${modelValue.title}`
          : `修改${modelValue.title}`
      "
				width="550px"
		>
			<div style="padding-right: 50px; padding-top: 20px">
<el-form
		:model="modelValue.form"
		:rules="modelValue.rules"
		ref="addEditRef"
		:label-width="100"
>
	<el-form-item label="记录唯一ID" prop="uuid">
		<el-input
				placeholder="请输入记录唯一ID"
				v-model="modelValue.form.uuid"
				autocomplete="off"
		/>
	</el-form-item>
	<el-form-item label="门店名称" prop="storeName">
		<el-input
				placeholder="请输入门店名称"
				v-model="modelValue.form.storeName"
				autocomplete="off"
		/>
	</el-form-item>
	<el-form-item label="客户端创建时间" prop="clientCreateTime">
		<el-input
				placeholder="请输入客户端创建时间"
				v-model="modelValue.form.clientCreateTime"
				autocomplete="off"
		/>
	</el-form-item>
	<el-form-item label="客户端完成时间" prop="clientFinishTime">
		<el-input
				placeholder="请输入客户端完成时间"
				v-model="modelValue.form.clientFinishTime"
				autocomplete="off"
		/>
	</el-form-item>
	<el-form-item label="客户端开始时间" prop="clientStartTime">
		<el-input
				placeholder="请输入客户端开始时间"
				v-model="modelValue.form.clientStartTime"
				autocomplete="off"
		/>
	</el-form-item>
	<el-form-item label="产品编号" prop="productNumber">
		<el-input
				placeholder="请输入产品编号"
				v-model="modelValue.form.productNumber"
				autocomplete="off"
		/>
	</el-form-item>
	<el-form-item label="菜单名称" prop="menuName">
		<el-input
				placeholder="请输入菜单名称"
				v-model="modelValue.form.menuName"
				autocomplete="off"
		/>
	</el-form-item>
	<el-form-item label="出杯速度（杯/秒）" prop="cupOutSpeed">
		<el-input
				placeholder="请输入出杯速度（杯/秒）"
				v-model="modelValue.form.cupOutSpeed"
				autocomplete="off"
		/>
	</el-form-item>
	<el-form-item label="物料消耗值" prop="materialValue">
		<el-input
				placeholder="请输入物料消耗值"
				v-model="modelValue.form.materialValue"
				autocomplete="off"
		/>
	</el-form-item>
	<el-form-item label="预估物料值" prop="estimateValue">
		<el-input
				placeholder="请输入预估物料值"
				v-model="modelValue.form.estimateValue"
				autocomplete="off"
		/>
	</el-form-item>
	<el-form-item label="物料消耗值（字符串）" prop="materialValueStr">
		<el-input
				placeholder="请输入物料消耗值（字符串）"
				v-model="modelValue.form.materialValueStr"
				autocomplete="off"
		/>
	</el-form-item>
	<el-form-item label="预估物料值（字符串）" prop="estimateValueStr">
		<el-input
				placeholder="请输入预估物料值（字符串）"
				v-model="modelValue.form.estimateValueStr"
				autocomplete="off"
		/>
	</el-form-item>
	<el-form-item label="缺失值" prop="missValue">
		<el-input
				placeholder="请输入缺失值"
				v-model="modelValue.form.missValue"
				autocomplete="off"
		/>
	</el-form-item>
	<el-form-item label="缺失值（双精度）" prop="missValueDouble">
		<el-input
				placeholder="请输入缺失值（双精度）"
				v-model="modelValue.form.missValueDouble"
				autocomplete="off"
		/>
	</el-form-item>
	<el-form-item label="门店编号" prop="storeNumber">
		<el-input
				placeholder="请输入门店编号"
				v-model="modelValue.form.storeNumber"
				autocomplete="off"
		/>
	</el-form-item>
	<el-form-item label="出杯速度（字符串，带单位）" prop="cupOutSpeedString">
		<el-input
				placeholder="请输入出杯速度（字符串，带单位）"
				v-model="modelValue.form.cupOutSpeedString"
				autocomplete="off"
		/>
	</el-form-item>
	<el-form-item label="出杯数量" prop="quantity">
		<el-input
				placeholder="请输入出杯数量"
				v-model="modelValue.form.quantity"
				autocomplete="off"
		/>
	</el-form-item>
	<el-form-item label="规格名称" prop="specName">
		<el-input
				placeholder="请输入规格名称"
				v-model="modelValue.form.specName"
				autocomplete="off"
		/>
	</el-form-item>
	<el-form-item label="机器唯一ID" prop="machineUuid">
		<el-input
				placeholder="请输入机器唯一ID"
				v-model="modelValue.form.machineUuid"
				autocomplete="off"
		/>
	</el-form-item>
	<el-form-item label="倒料时间（秒）" prop="pouringTime">
		<el-input
				placeholder="请输入倒料时间（秒）"
				v-model="modelValue.form.pouringTime"
				autocomplete="off"
		/>
	</el-form-item>
	<el-form-item label="倒料时间（字符串，带单位）" prop="pouringTimeStr">
		<el-input
				placeholder="请输入倒料时间（字符串，带单位）"
				v-model="modelValue.form.pouringTimeStr"
				autocomplete="off"
		/>
	</el-form-item>
	<el-form-item label="操作时间（秒）" prop="operateTime">
		<el-input
				placeholder="请输入操作时间（秒）"
				v-model="modelValue.form.operateTime"
				autocomplete="off"
		/>
	</el-form-item>
	<el-form-item label="操作时间（字符串，带单位）" prop="operateTimeStr">
		<el-input
				placeholder="请输入操作时间（字符串，带单位）"
				v-model="modelValue.form.operateTimeStr"
				autocomplete="off"
		/>
	</el-form-item>

</el-form>
			</div>
			<template #footer v-if="!modelValue.form.disabled">
        <span class="dialog-footer">
          <el-button @click="cancel">取消</el-button>
          <el-button type="primary" @click="ensure"> 确定 </el-button>
        </span>
			</template>
		</el-dialog>
	</div>
</template>
<script  setup lang='ts'>
	import { ref, onMounted } from "vue";
	import { ElMessage, FormInstance } from "element-plus";
	import { addOrrOutcupEfficiencyDetail, updateOrrOutcupEfficiencyDetail } from "@/api/orr-outcup-efficiency-detail.api";

	const props = defineProps(["modelValue"]);
	const addEditRef = ref<FormInstance>();

	/***
	 * 确认弹框
	 */
	const ensure = () => {
		let form = props.modelValue.form;
		let formData = {
																				uuid: form.uuid,
																	storeName: form.storeName,
																	clientCreateTime: form.clientCreateTime,
																	clientFinishTime: form.clientFinishTime,
																	clientStartTime: form.clientStartTime,
																	productNumber: form.productNumber,
																	menuName: form.menuName,
																	cupOutSpeed: form.cupOutSpeed,
																	materialValue: form.materialValue,
																	estimateValue: form.estimateValue,
																	materialValueStr: form.materialValueStr,
																	estimateValueStr: form.estimateValueStr,
																	missValue: form.missValue,
																	missValueDouble: form.missValueDouble,
																	storeNumber: form.storeNumber,
																	cupOutSpeedString: form.cupOutSpeedString,
																	quantity: form.quantity,
																	specName: form.specName,
																	machineUuid: form.machineUuid,
																	pouringTime: form.pouringTime,
																	pouringTimeStr: form.pouringTimeStr,
																	operateTime: form.operateTime,
																	operateTimeStr: form.operateTimeStr,
																																												};

		if (!addEditRef.value) return;
		addEditRef.value.validate((valid, fields) => {
			if (valid) {
				if (form.id) {
					updateOrrOutcupEfficiencyDetail({
						...formData,
						id: form.id,
					})
							.then((res) => {
								cancel();
								ElMessage({
									message: props.modelValue.title + "修改成功",
									type: "success",
								});
								if (props.modelValue.refreshDataList) {
									props.modelValue.refreshDataList();
								}
							})
							.catch((err) => {
								ElMessage({
									message: err.msg || err,
									type: "error",
								});
							});
					return;
				}

				addOrrOutcupEfficiencyDetail(formData)
						.then((res) => {
							cancel();
							ElMessage({
								message: props.modelValue.title + "新增成功",
								type: "success",
							});
							if (props.modelValue.refreshDataList) {
								props.modelValue.refreshDataList();
							}
						})
						.catch((err) => {
							ElMessage({
								message: err.msg || err,
								type: "error",
							});
						});
			}
		});
	};

	/***
	 * 取消弹框
	 */
	const cancel = () => {
		props.modelValue.visible = false;
	};

</script>
<style lang='scss' scoped>
</style>
